<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>递归处理树数据的排序</title>
</head>

<body>
<script>
let data = {
    "code": "0",
    "isSuccess": true,
    "message": "ok!",
    "errorCode": "0",
    "data": [
        {
            "nodeId": "316958050613198848",
            "nodeName": "外墙",
            "level": 1,
            "completeTimeLimit": "10.00",
            "sBigCategoryId": "316950756533993472",
            "sBigCategoryName": "公区报修",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316958050613198848",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 2,
            "updateDate": 1598845303000,
            "childList": [
                {
                    "nodeId": "316958099376177152",
                    "nodeName": "A栋外墙",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993472",
                    "sBigCategoryName": "公区报修",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316958050613198848,316958099376177152",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1577430662000,
                    "childList": [
                        {
                            "nodeId": "316958504420114432",
                            "nodeName": "朝西外墙",
                            "level": 3,
                            "completeTimeLimit": "10.00",
                            "sBigCategoryId": "316950756533993472",
                            "sBigCategoryName": "公区报修",
                            "positionIds": "236,235,238,237,240,239,254,253,252,255,242,241,243",
                            "positionNames": "客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,董事长,副总经理,总经理,项目经理,会计,财务总监,工程师",
                            "nodePath": "316958050613198848,316958099376177152,316958504420114432",
                            "effectiveness": 0,
                            "enableSubclass": 1,
                            "sort": 0,
                            "updateDate": 1596164639000,
                            "childList": []
                        }
                    ]
                },
                {
                    "nodeId": "316958241886044160",
                    "nodeName": "B栋外墙",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993472",
                    "sBigCategoryName": "公区报修",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316958050613198848,316958241886044160",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1558768734000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "472848835824062464",
            "nodeName": "测试111",
            "level": 1,
            "completeTimeLimit": "1.00",
            "sBigCategoryId": "316950756533993473",
            "sBigCategoryName": "室内报修",
            "positionIds": "236,235,238,237,240,239,244,254,253,252,255,242,241,243",
            "positionNames": "客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,软件实施顾问,董事长,副总经理,总经理,项目经理,会计,财务总监,工程师",
            "nodePath": "472848835824062464",
            "effectiveness": 1,
            "enableSubclass": 1,
            "sort": 0,
            "updateDate": 1598499904000,
            "childList": [
                {
                    "nodeId": "472849514290479104",
                    "nodeName": "2222",
                    "level": 2,
                    "completeTimeLimit": "1.00",
                    "sBigCategoryId": "316950756533993473",
                    "sBigCategoryName": "室内报修",
                    "positionIds": "236,235,238,237,240,239,244,254,253,252,255,242,241,243",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,软件实施顾问,董事长,副总经理,总经理,项目经理,会计,财务总监,工程师",
                    "nodePath": "472848835824062464,472849514290479104",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1595936109000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "323485062907564032",
            "nodeName": "强电",
            "level": 1,
            "completeTimeLimit": "5.00",
            "sBigCategoryId": "316950756533993473",
            "sBigCategoryName": "室内报修",
            "positionIds": "244",
            "positionNames": "软件实施顾问",
            "nodePath": "323485062907564032",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1577430878000,
            "childList": [
                {
                    "nodeId": "326009244019068928",
                    "nodeName": "变压器",
                    "level": 2,
                    "completeTimeLimit": "1.00",
                    "sBigCategoryId": "316950756533993473",
                    "sBigCategoryName": "室内报修",
                    "positionIds": "244",
                    "positionNames": "软件实施顾问",
                    "nodePath": "323485062907564032,326009244019068928",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 2,
                    "updateDate": 1598845280000,
                    "childList": []
                },
                {
                    "nodeId": "323485199306330112",
                    "nodeName": "照明",
                    "level": 2,
                    "completeTimeLimit": "2.00",
                    "sBigCategoryId": "316950756533993473",
                    "sBigCategoryName": "室内报修",
                    "positionIds": "244",
                    "positionNames": "软件实施顾问",
                    "nodePath": "323485062907564032,323485199306330112",
                    "effectiveness": 0,
                    "enableSubclass": 0,
                    "sort": 0,
                    "updateDate": 1560324882000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "317976623238348800",
            "nodeName": "其他",
            "level": 1,
            "completeTimeLimit": "10.00",
            "sBigCategoryId": "316950756533993472",
            "sBigCategoryName": "公区报修",
            "positionIds": "242,241,236,235,238,237,240,239,243,244",
            "positionNames": "会计,财务总监,客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,研发工程师,软件实施顾问",
            "nodePath": "317976623238348800",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1560133734000,
            "childList": [
                {
                    "nodeId": "317976702791712768",
                    "nodeName": "其他",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993472",
                    "sBigCategoryName": "公区报修",
                    "positionIds": "242,241,236,235,238,237,240,239,243,244",
                    "positionNames": "会计,财务总监,客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,研发工程师,软件实施顾问",
                    "nodePath": "317976623238348800,317976702791712768",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1560133718000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316959605047427072",
            "nodeName": "天花贴面",
            "level": 1,
            "completeTimeLimit": "3.00",
            "sBigCategoryId": "316950756533993473",
            "sBigCategoryName": "室内报修",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316959605047427072",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558769059000,
            "childList": [
                {
                    "nodeId": "316959751323779072",
                    "nodeName": "天花清洁",
                    "level": 2,
                    "completeTimeLimit": "2.00",
                    "sBigCategoryId": "316950756533993473",
                    "sBigCategoryName": "室内报修",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959605047427072,316959751323779072",
                    "effectiveness": 0,
                    "enableSubclass": 0,
                    "sort": 0,
                    "updateDate": 1558769094000,
                    "childList": []
                },
                {
                    "nodeId": "316959663985786880",
                    "nodeName": "天花板装修",
                    "level": 2,
                    "completeTimeLimit": "3.00",
                    "sBigCategoryId": "316950756533993473",
                    "sBigCategoryName": "室内报修",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959605047427072,316959663985786880",
                    "effectiveness": 0,
                    "enableSubclass": 0,
                    "sort": 0,
                    "updateDate": 1558769073000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316959473711185920",
            "nodeName": "寻求帮助",
            "level": 1,
            "completeTimeLimit": "3.00",
            "sBigCategoryId": "316950756533993475",
            "sBigCategoryName": "其他服务",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316959473711185920",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558769027000,
            "childList": [
                {
                    "nodeId": "316959800258723840",
                    "nodeName": "家政服务",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993475",
                    "sBigCategoryName": "其他服务",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959473711185920,316959800258723840",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1558769105000,
                    "childList": []
                },
                {
                    "nodeId": "316959517738795008",
                    "nodeName": "物业求助",
                    "level": 2,
                    "completeTimeLimit": "3.00",
                    "sBigCategoryId": "316950756533993475",
                    "sBigCategoryName": "其他服务",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959473711185920,316959517738795008",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1558769038000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316959266390933504",
            "nodeName": "业主诉求",
            "level": 1,
            "completeTimeLimit": "10.00",
            "sBigCategoryId": "316950756533993475",
            "sBigCategoryName": "其他服务",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316959266390933504",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558768978000,
            "childList": [
                {
                    "nodeId": "317976759339319296",
                    "nodeName": "其他",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993475",
                    "sBigCategoryName": "其他服务",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959266390933504,317976759339319296",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1559011567000,
                    "childList": []
                },
                {
                    "nodeId": "316959349136162816",
                    "nodeName": "诉求",
                    "level": 2,
                    "completeTimeLimit": "3.00",
                    "sBigCategoryId": "316950756533993475",
                    "sBigCategoryName": "其他服务",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959266390933504,316959349136162816",
                    "effectiveness": 0,
                    "enableSubclass": 0,
                    "sort": 0,
                    "updateDate": 1558768998000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316959100598484992",
            "nodeName": "物业建议",
            "level": 1,
            "completeTimeLimit": "3.00",
            "sBigCategoryId": "316950756533993474",
            "sBigCategoryName": "投诉建议",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316959100598484992",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558768938000,
            "childList": [
                {
                    "nodeId": "317976805904482304",
                    "nodeName": "其他",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993474",
                    "sBigCategoryName": "投诉建议",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959100598484992,317976805904482304",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1559011578000,
                    "childList": []
                },
                {
                    "nodeId": "316959152129703936",
                    "nodeName": "建议意见",
                    "level": 2,
                    "completeTimeLimit": "3.00",
                    "sBigCategoryId": "316950756533993474",
                    "sBigCategoryName": "投诉建议",
                    "positionIds": "236,235,238,237",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员",
                    "nodePath": "316959100598484992,316959152129703936",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1558768951000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316958861506379776",
            "nodeName": "投诉物业",
            "level": 1,
            "completeTimeLimit": "10.00",
            "sBigCategoryId": "316950756533993474",
            "sBigCategoryName": "投诉建议",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316958861506379776",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558768904000,
            "childList": [
                {
                    "nodeId": "316958931966492672",
                    "nodeName": "服务态度",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993474",
                    "sBigCategoryName": "投诉建议",
                    "positionIds": "242,241,236,235,238,237,240,239,243,244",
                    "positionNames": "会计,财务总监,客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,研发工程师,软件实施顾问",
                    "nodePath": "316958861506379776,316958931966492672",
                    "effectiveness": 0,
                    "enableSubclass": 0,
                    "sort": 0,
                    "updateDate": 1560398534000,
                    "childList": []
                },
                {
                    "nodeId": "316959914578673664",
                    "nodeName": "员工着装",
                    "level": 2,
                    "completeTimeLimit": "3.00",
                    "sBigCategoryId": "316950756533993474",
                    "sBigCategoryName": "投诉建议",
                    "positionIds": "242,241,236,235,238,237,240,239,243,244",
                    "positionNames": "会计,财务总监,客服主管,客服专员,品质主管,品质专员,产品经理,产品总监,研发工程师,软件实施顾问",
                    "nodePath": "316958861506379776,316959914578673664",
                    "effectiveness": 0,
                    "enableSubclass": 0,
                    "sort": 0,
                    "updateDate": 1560398522000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316958657004699648",
            "nodeName": "厨房",
            "level": 1,
            "completeTimeLimit": "30.00",
            "sBigCategoryId": "316950756533993473",
            "sBigCategoryName": "室内报修",
            "positionIds": "236,235,238,237",
            "positionNames": "客服主管,客服专员,品质主管,品质专员",
            "nodePath": "316958657004699648",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558768846000,
            "childList": [
                {
                    "nodeId": "316958765511344128",
                    "nodeName": "下水道",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993473",
                    "sBigCategoryName": "室内报修",
                    "positionIds": "236,235,238,237,244",
                    "positionNames": "客服主管,客服专员,品质主管,品质专员,软件实施顾问",
                    "nodePath": "316958657004699648,316958765511344128",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1559292703000,
                    "childList": []
                }
            ]
        },
        {
            "nodeId": "316957948452536320",
            "nodeName": "大堂前台",
            "level": 1,
            "completeTimeLimit": "10.00",
            "sBigCategoryId": "316950756533993472",
            "sBigCategoryName": "公区报修",
            "positionIds": "236,235",
            "positionNames": "客服主管,客服专员",
            "nodePath": "316957948452536320",
            "effectiveness": 0,
            "enableSubclass": 0,
            "sort": 0,
            "updateDate": 1558768664000,
            "childList": [
                {
                    "nodeId": "316958377089433600",
                    "nodeName": "B栋前台",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993472",
                    "sBigCategoryName": "公区报修",
                    "positionIds": "236,235",
                    "positionNames": "客服主管,客服专员",
                    "nodePath": "316957948452536320,316958377089433600",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1558768766000,
                    "childList": []
                },
                {
                    "nodeId": "316958187095851008",
                    "nodeName": "A栋前台",
                    "level": 2,
                    "completeTimeLimit": "10.00",
                    "sBigCategoryId": "316950756533993472",
                    "sBigCategoryName": "公区报修",
                    "positionIds": "236,235",
                    "positionNames": "客服主管,客服专员",
                    "nodePath": "316957948452536320,316958187095851008",
                    "effectiveness": 0,
                    "enableSubclass": 1,
                    "sort": 0,
                    "updateDate": 1558768721000,
                    "childList": []
                }
            ]
        }
    ]
};

let treeData = data.data;

function loop(obj) {
    let childList = obj.childList || [];
    childList.sort((a, b) => a.sort - b.sort);
    childList.forEach(element => {
        loop(element);
    });
}

treeData.forEach(treeItem => {
    loop(treeItem);
})

console.dir(treeData);

</script>
</body>

</html>